﻿using GHI.Glide;
using GHI.Glide.Display;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation.Media;
using System.Threading;
using Timer = Gadgeteer.Timer;

namespace TweenTest
{
	public partial class Program
	{
		private Window _window;
		private Timer _timer;

		void ProgramStarted()
		{
			Debug.Print("Program Started");

			_window = GlideLoader.LoadWindow(Resources.GetString(Resources.StringResources.window));

			_timer = new Timer(1000);
			_timer.Tick += timer_Tick;
			_timer.Start();
		}

		void timer_Tick(Timer timer)
		{
			timer.Stop();
			Start();
		}

		private void Start()
		{
			PJE.GlideEx.Tween.Expand(_window, PJE.GlideEx.Direction.Top, Color.Black);
			Thread.Sleep(1000);
			PJE.GlideEx.Tween.FadeOut(_window, Color.Black);
			Thread.Sleep(1000);
			PJE.GlideEx.Tween.Expand(_window, PJE.GlideEx.Direction.Bottom, Color.Black);
			Thread.Sleep(1000);
			PJE.GlideEx.Tween.FadeOut(_window, Color.Black);
			Thread.Sleep(1000);
			PJE.GlideEx.Tween.Expand(_window, PJE.GlideEx.Direction.Left, Color.Black);
			Thread.Sleep(1000);
			PJE.GlideEx.Tween.FadeOut(_window, Color.Black);
			Thread.Sleep(1000);
			PJE.GlideEx.Tween.Expand(_window, PJE.GlideEx.Direction.Right, Color.Black);
			Thread.Sleep(1000);
			PJE.GlideEx.Tween.FadeOut(_window, Color.Black);
			Thread.Sleep(1000);
			PJE.GlideEx.Tween.Expand(_window, PJE.GlideEx.Direction.TopLeft, Color.Black);
			Thread.Sleep(1000);
			PJE.GlideEx.Tween.FadeOut(_window, Color.Black);
			Thread.Sleep(1000);
			PJE.GlideEx.Tween.Expand(_window, PJE.GlideEx.Direction.TopRight, Color.Black);
			Thread.Sleep(1000);
			PJE.GlideEx.Tween.FadeOut(_window, Color.Black);
			Thread.Sleep(1000);
			PJE.GlideEx.Tween.Expand(_window, PJE.GlideEx.Direction.BottomLeft, Color.Black);
			Thread.Sleep(1000);
			PJE.GlideEx.Tween.FadeOut(_window, Color.Black);
			Thread.Sleep(1000);
			PJE.GlideEx.Tween.Expand(_window, PJE.GlideEx.Direction.BottomRight, Color.Black);
			Thread.Sleep(1000);
			PJE.GlideEx.Tween.Collapse(_window, PJE.GlideEx.Direction.Top, Color.Black);
			Thread.Sleep(1000);
			PJE.GlideEx.Tween.FadeIn(_window, Color.Black);
			Thread.Sleep(1000);
			PJE.GlideEx.Tween.Collapse(_window, PJE.GlideEx.Direction.Bottom, Color.Black);
			Thread.Sleep(1000);
			PJE.GlideEx.Tween.FadeIn(_window, Color.Black);
			Thread.Sleep(1000);
			PJE.GlideEx.Tween.Collapse(_window, PJE.GlideEx.Direction.Left, Color.Black);
			Thread.Sleep(1000);
			PJE.GlideEx.Tween.FadeIn(_window, Color.Black);
			Thread.Sleep(1000);
			PJE.GlideEx.Tween.Collapse(_window, PJE.GlideEx.Direction.Right, Color.Black);
			Thread.Sleep(1000);
			PJE.GlideEx.Tween.FadeIn(_window, Color.Black);
			Thread.Sleep(1000);
			PJE.GlideEx.Tween.Collapse(_window, PJE.GlideEx.Direction.TopLeft, Color.Black);
			Thread.Sleep(1000);
			PJE.GlideEx.Tween.FadeIn(_window, Color.Black);
			Thread.Sleep(1000);
			PJE.GlideEx.Tween.Collapse(_window, PJE.GlideEx.Direction.TopRight, Color.Black);
			Thread.Sleep(1000);
			PJE.GlideEx.Tween.FadeIn(_window, Color.Black);
			Thread.Sleep(1000);
			PJE.GlideEx.Tween.Collapse(_window, PJE.GlideEx.Direction.BottomLeft, Color.Black);
			Thread.Sleep(1000);
			PJE.GlideEx.Tween.FadeIn(_window, Color.Black);
			Thread.Sleep(1000);
			PJE.GlideEx.Tween.Collapse(_window, PJE.GlideEx.Direction.BottomRight, Color.Black);
			Thread.Sleep(1000);
			_timer.Tick += timer_Tick;
			_timer.Start();
		}
	}
}
